/*   1:    */ package com.sie.driver.ftusbdriver;
/*   2:    */ 
/*   3:    */

/*   4:    */
/*   5:    */ class FT_EE_245R_Ctrl
/*   6:    */   extends FT_EE_Ctrl
/*   7:    */ {
/*   8:    */   private static final short EEPROM_SIZE = 80;
/*   9:    */   private static final short ENDOFUSERLOCATION = 63;
/*  10:    */   private static final short EE_MAX_SIZE = 1024;
/*  11:    */   private static final int EXTERNAL_OSCILLATOR = 2;
/*  12:    */   private static final int HIGH_CURRENT_IO = 4;
/*  13:    */   private static final int LOAD_D2XX_DRIVER = 8;
/*  14:    */   private static final int INVERT_TXD = 256;
/*  15:    */   private static final int INVERT_RXD = 512;
/*  16:    */   private static final int INVERT_RTS = 1024;
/*  17:    */   private static final int INVERT_CTS = 2048;
/*  18:    */   private static final int INVERT_DTR = 4096;
/*  19:    */   private static final int INVERT_DSR = 8192;
/*  20:    */   private static final int INVERT_DCD = 16384;
/*  21:    */   private static final int INVERT_RI = 32768;
/*  22:    */   private static FT_Device ft_device;
/*  23:    */   
/*  24:    */   FT_EE_245R_Ctrl(FT_Device usbC)
/*  25:    */   {
/*  26: 23 */     super(usbC);
/*  27: 24 */     ft_device = usbC;
/*  28:    */   }
/*  29:    */   
/*  30:    */   boolean writeWord(short offset, short value)
/*  31:    */   {
/*  32: 30 */     int wValue = value & 0xFFFF;
/*  33: 31 */     int wIndex = offset & 0xFFFF;
/*  34: 32 */     int status = 0;
/*  35: 33 */     boolean rc = false;
/*  36: 34 */     byte latency = 0;
/*  37: 36 */     if (offset >= 1024) {
/*  38: 38 */       return rc;
/*  39:    */     }
/*  40: 40 */     latency = ft_device.getLatencyTimer();
/*  41: 41 */     ft_device.setLatencyTimer((byte)119);
/*  42:    */     
/*  43: 43 */     status = ft_device.getConnection().controlTransfer(64, 
/*  44:    */     
/*  45:    */ 
/*  46: 46 */       145, 
/*  47: 47 */       wValue, 
/*  48: 48 */       wIndex, 
/*  49: 49 */       null, 
/*  50: 50 */       0, 
/*  51: 51 */       0);
/*  52: 53 */     if (status == 0) {
/*  53: 53 */       rc = true;
/*  54:    */     }
/*  55: 55 */     ft_device.setLatencyTimer(latency);
/*  56:    */     
/*  57: 57 */     return rc;
/*  58:    */   }
/*  59:    */   
/*  60:    */   short programEeprom(FT_EEPROM ee)
/*  61:    */   {
/*  62: 62 */     int[] data = new int[80];
/*  63: 68 */     if (ee.getClass() != FT_EEPROM_245R.class) {
/*  64: 69 */       return 1;
/*  65:    */     }
/*  66: 71 */     FT_EEPROM_245R eeprom = (FT_EEPROM_245R)ee;
/*  67:    */     try
/*  68:    */     {
/*  69: 75 */       for (short i = 0; i < 80; i = (short)(i + 1)) {
/*  70: 76 */         data[i] = readWord(i);
/*  71:    */       }
/*  72: 83 */       int wordx00 = 0;
/*  73:    */       
/*  74: 85 */       wordx00 |= data[0] & 0xFF00;
/*  75: 86 */       if (eeprom.HighIO) {
/*  76: 88 */         wordx00 |= 0x4;
/*  77:    */       }
/*  78: 90 */       if (eeprom.LoadVCP) {
/*  79: 92 */         wordx00 |= 0x8;
/*  80:    */       }
/*  81: 96 */       if (eeprom.ExternalOscillator) {
/*  82: 98 */         wordx00 |= 0x2;
/*  83:    */       } else {
/*  84:102 */         wordx00 &= 0xFFFD;
/*  85:    */       }
/*  86:104 */       data[0] = wordx00;
/*  87:    */       
/*  88:    */ 
/*  89:    */ 
/*  90:    */ 
/*  91:109 */       data[1] = eeprom.VendorId;
/*  92:    */       
/*  93:    */ 
/*  94:    */ 
/*  95:    */ 
/*  96:114 */       data[2] = eeprom.ProductId;
/*  97:    */       
/*  98:    */ 
/*  99:    */ 
/* 100:    */ 
/* 101:119 */       data[3] = 1536;
/* 102:    */       
/* 103:    */ 
/* 104:    */ 
/* 105:    */ 
/* 106:124 */       data[4] = setUSBConfig(ee);
/* 107:    */       
/* 108:    */ 
/* 109:    */ 
/* 110:    */ 
/* 111:129 */       int wordx05 = setDeviceControl(ee);
/* 112:130 */       if (eeprom.InvertTXD) {
/* 113:131 */         wordx05 |= 0x100;
/* 114:    */       }
/* 115:132 */       if (eeprom.InvertRXD) {
/* 116:133 */         wordx05 |= 0x200;
/* 117:    */       }
/* 118:134 */       if (eeprom.InvertRTS) {
/* 119:135 */         wordx05 |= 0x400;
/* 120:    */       }
/* 121:136 */       if (eeprom.InvertCTS) {
/* 122:137 */         wordx05 |= 0x800;
/* 123:    */       }
/* 124:138 */       if (eeprom.InvertDTR) {
/* 125:139 */         wordx05 |= 0x1000;
/* 126:    */       }
/* 127:140 */       if (eeprom.InvertDSR) {
/* 128:141 */         wordx05 |= 0x2000;
/* 129:    */       }
/* 130:142 */       if (eeprom.InvertDCD) {
/* 131:143 */         wordx05 |= 0x4000;
/* 132:    */       }
/* 133:144 */       if (eeprom.InvertRI) {
/* 134:145 */         wordx05 |= 0x8000;
/* 135:    */       }
/* 136:147 */       data[5] = wordx05;
/* 137:    */       
/* 138:    */ 
/* 139:    */ 
/* 140:    */ 
/* 141:152 */       int wordx0A = 0;
/* 142:153 */       int c0 = eeprom.CBus0;
/* 143:154 */       int c1 = eeprom.CBus1;
/* 144:155 */       c1 <<= 4;
/* 145:156 */       int c2 = eeprom.CBus2;
/* 146:157 */       c2 <<= 8;
/* 147:158 */       int c3 = eeprom.CBus3;
/* 148:159 */       c3 <<= 12;
/* 149:160 */       wordx0A = c0 | c1 | c2 | c3;
/* 150:161 */       data[10] = wordx0A;
/* 151:    */       
/* 152:    */ 
/* 153:    */ 
/* 154:    */ 
/* 155:166 */       int wordx0B = 0;
/* 156:167 */       int c4 = eeprom.CBus4;
/* 157:168 */       wordx0B = c4;
/* 158:169 */       data[11] = wordx0B;
/* 159:    */       
/* 160:    */ 
/* 161:    */ 
/* 162:    */ 
/* 163:174 */       int saddr = 12;
/* 164:175 */       saddr = setStringDescriptor(eeprom.Manufacturer, data, saddr, 7, true);
/* 165:    */       
/* 166:    */ 
/* 167:    */ 
/* 168:    */ 
/* 169:180 */       saddr = setStringDescriptor(eeprom.Product, data, saddr, 8, true);
/* 170:185 */       if (eeprom.SerNumEnable) {
/* 171:186 */         saddr = setStringDescriptor(eeprom.SerialNumber, data, saddr, 9, true);
/* 172:    */       }
/* 173:189 */       byte latency = 0;
/* 174:191 */       if ((data[1] != 0) && (data[2] != 0))
/* 175:    */       {
/* 176:193 */         boolean returnCode = false;
/* 177:    */         
/* 178:    */ 
/* 179:196 */         latency = ft_device.getLatencyTimer();
/* 180:197 */         ft_device.setLatencyTimer((byte)119);
/* 181:198 */         returnCode = programEeprom(data, 80);
/* 182:199 */         ft_device.setLatencyTimer(latency);
/* 183:200 */         if (returnCode) {
/* 184:201 */           return 0;
/* 185:    */         }
/* 186:203 */         return 1;
/* 187:    */       }
/* 188:207 */       return 2;
/* 189:    */     }
/* 190:    */     catch (Exception e)
/* 191:    */     {
/* 192:213 */       e.printStackTrace();
/* 193:    */     }
/* 194:215 */     return 0;
/* 195:    */   }
/* 196:    */   
/* 197:    */   FT_EEPROM readEeprom()
/* 198:    */   {
/* 199:221 */     FT_EEPROM_245R eeprom = new FT_EEPROM_245R();
/* 200:222 */     int[] data = new int[80];
/* 201:    */     try
/* 202:    */     {
/* 203:226 */       for (int i = 0; i < 80; i++) {
/* 204:228 */         data[i] = readWord((short)i);
/* 205:    */       }
/* 206:234 */       if ((data[0] & 0x4) == 4) {
/* 207:235 */         eeprom.HighIO = true;
/* 208:    */       } else {
/* 209:237 */         eeprom.HighIO = false;
/* 210:    */       }
/* 211:240 */       if ((data[0] & 0x8) == 8) {
/* 212:241 */         eeprom.LoadVCP = true;
/* 213:    */       } else {
/* 214:243 */         eeprom.LoadVCP = false;
/* 215:    */       }
/* 216:246 */       if ((data[0] & 0x2) == 2) {
/* 217:247 */         eeprom.ExternalOscillator = true;
/* 218:    */       } else {
/* 219:249 */         eeprom.ExternalOscillator = false;
/* 220:    */       }
/* 221:254 */       eeprom.VendorId = ((short)data[1]);
/* 222:    */       
/* 223:    */ 
/* 224:    */ 
/* 225:    */ 
/* 226:259 */       eeprom.ProductId = ((short)data[2]);
/* 227:    */       
/* 228:    */ 
/* 229:    */ 
/* 230:    */ 
/* 231:    */ 
/* 232:    */ 
/* 233:    */ 
/* 234:    */ 
/* 235:    */ 
/* 236:    */ 
/* 237:270 */       getUSBConfig(eeprom, data[4]);
/* 238:    */       
/* 239:    */ 
/* 240:    */ 
/* 241:    */ 
/* 242:275 */       getDeviceControl(eeprom, data[5]);
/* 243:278 */       if ((data[5] & 0x100) == 256) {
/* 244:279 */         eeprom.InvertTXD = true;
/* 245:    */       } else {
/* 246:281 */         eeprom.InvertTXD = false;
/* 247:    */       }
/* 248:283 */       if ((data[5] & 0x200) == 512) {
/* 249:284 */         eeprom.InvertRXD = true;
/* 250:    */       } else {
/* 251:286 */         eeprom.InvertRXD = false;
/* 252:    */       }
/* 253:288 */       if ((data[5] & 0x400) == 1024) {
/* 254:289 */         eeprom.InvertRTS = true;
/* 255:    */       } else {
/* 256:291 */         eeprom.InvertRTS = false;
/* 257:    */       }
/* 258:293 */       if ((data[5] & 0x800) == 2048) {
/* 259:294 */         eeprom.InvertCTS = true;
/* 260:    */       } else {
/* 261:296 */         eeprom.InvertCTS = false;
/* 262:    */       }
/* 263:298 */       if ((data[5] & 0x1000) == 4096) {
/* 264:299 */         eeprom.InvertDTR = true;
/* 265:    */       } else {
/* 266:301 */         eeprom.InvertDTR = false;
/* 267:    */       }
/* 268:303 */       if ((data[5] & 0x2000) == 8192) {
/* 269:304 */         eeprom.InvertDSR = true;
/* 270:    */       } else {
/* 271:306 */         eeprom.InvertDSR = false;
/* 272:    */       }
/* 273:308 */       if ((data[5] & 0x4000) == 16384) {
/* 274:309 */         eeprom.InvertDCD = true;
/* 275:    */       } else {
/* 276:311 */         eeprom.InvertDCD = false;
/* 277:    */       }
/* 278:313 */       if ((data[5] & 0x8000) == 32768) {
/* 279:314 */         eeprom.InvertRI = true;
/* 280:    */       } else {
/* 281:316 */         eeprom.InvertRI = false;
/* 282:    */       }
/* 283:322 */       int temp = data[10];
/* 284:323 */       int cbus0 = temp & 0xF;
/* 285:324 */       eeprom.CBus0 = ((byte)cbus0);
/* 286:    */       
/* 287:326 */       int cbus1 = temp & 0xF0;
/* 288:327 */       eeprom.CBus1 = ((byte)(cbus1 >> 4));
/* 289:    */       
/* 290:329 */       int cbus2 = temp & 0xF00;
/* 291:330 */       eeprom.CBus2 = ((byte)(cbus2 >> 8));
/* 292:    */       
/* 293:332 */       int cbus3 = temp & 0xF000;
/* 294:333 */       eeprom.CBus3 = ((byte)(cbus3 >> 12));
/* 295:    */       
/* 296:    */ 
/* 297:    */ 
/* 298:    */ 
/* 299:    */ 
/* 300:339 */       int cbus4 = data[11] & 0xFF;
/* 301:340 */       eeprom.CBus4 = ((byte)cbus4);
/* 302:    */       
/* 303:    */ 
/* 304:    */ 
/* 305:    */ 
/* 306:345 */       int addr = data[7] & 0xFF;
/* 307:346 */       addr -= 128;
/* 308:347 */       addr /= 2;
/* 309:348 */       eeprom.Manufacturer = getStringDescriptor(addr, data);
/* 310:349 */       addr = data[8] & 0xFF;
/* 311:350 */       addr -= 128;
/* 312:351 */       addr /= 2;
/* 313:352 */       eeprom.Product = getStringDescriptor(addr, data);
/* 314:353 */       addr = data[9] & 0xFF;
/* 315:354 */       addr -= 128;
/* 316:355 */       addr /= 2;
/* 317:356 */       eeprom.SerialNumber = getStringDescriptor(addr, data);
/* 318:    */       
/* 319:358 */       return eeprom;
/* 320:    */     }
/* 321:    */     catch (Exception e) {}
/* 322:363 */     return null;
/* 323:    */   }
/* 324:    */   
/* 325:    */   int getUserSize()
/* 326:    */   {
/* 327:371 */     int data = readWord((short)7);
/* 328:372 */     int ptr07 = (data & 0xFF00) >> 8;
/* 329:373 */     ptr07 /= 2;
/* 330:    */     
/* 331:    */ 
/* 332:376 */     data = readWord((short)8);
/* 333:377 */     int ptr08 = (data & 0xFF00) >> 8;
/* 334:378 */     ptr08 /= 2;
/* 335:    */     
/* 336:    */ 
/* 337:    */ 
/* 338:    */ 
/* 339:383 */     int ptr = 12 + ptr07 + ptr08 + 1;
/* 340:    */     
/* 341:    */ 
/* 342:386 */     data = readWord((short)9);
/* 343:387 */     int length = (data & 0xFF00) >> 8;
/* 344:388 */     length /= 2;
/* 345:    */     
/* 346:    */ 
/* 347:391 */     return (63 - ptr - length - 1) * 2;
/* 348:    */   }
/* 349:    */   
/* 350:    */   int writeUserData(byte[] data)
/* 351:    */   {
/* 352:397 */     int dataWrite = 0;
/* 353:398 */     short offset = 0;
/* 354:400 */     if (data.length > getUserSize()) {
/* 355:401 */       return 0;
/* 356:    */     }
/* 357:403 */     int[] eeprom = new int[80];
/* 358:405 */     for (short i = 0; i < 80; i = (short)(i + 1)) {
/* 359:406 */       eeprom[i] = readWord(i);
/* 360:    */     }
/* 361:409 */     offset = (short)(63 - getUserSize() / 2 - 1);
/* 362:410 */     offset = (short)(offset & 0xFFFF);
/* 363:412 */     for (int i = 0; i < data.length; i += 2)
/* 364:    */     {
/* 365:414 */       if (i + 1 < data.length) {
/* 366:415 */         dataWrite = data[(i + 1)] & 0xFF;
/* 367:    */       } else {
/* 368:417 */         dataWrite = 0;
/* 369:    */       }
/* 370:419 */       dataWrite <<= 8;
/* 371:420 */       dataWrite |= data[i] & 0xFF;
/* 372:    */       
/* 373:422 */       eeprom[(offset++)] = dataWrite;
/* 374:    */     }
/* 375:425 */     byte latency = 0;
/* 376:427 */     if ((eeprom[1] != 0) && (eeprom[2] != 0))
/* 377:    */     {
/* 378:429 */       boolean returnCode = false;
/* 379:430 */       latency = ft_device.getLatencyTimer();
/* 380:431 */       ft_device.setLatencyTimer((byte)119);
/* 381:432 */       returnCode = programEeprom(eeprom, 63);
/* 382:433 */       ft_device.setLatencyTimer(latency);
/* 383:434 */       if (!returnCode) {
/* 384:435 */         return 0;
/* 385:    */       }
/* 386:    */     }
/* 387:    */     else
/* 388:    */     {
/* 389:439 */       return 0;
/* 390:    */     }
/* 391:442 */     return data.length;
/* 392:    */   }
/* 393:    */   
/* 394:    */   byte[] readUserData(int length)
/* 395:    */   {
/* 396:448 */     byte Hi = 0;
/* 397:449 */     byte Lo = 0;
/* 398:450 */     int dataRead = 0;
/* 399:451 */     byte[] data = new byte[length];
/* 400:453 */     if ((length == 0) || (length > getUserSize())) {
/* 401:454 */       return null;
/* 402:    */     }
/* 403:456 */     short offset = (short)(63 - getUserSize() / 2 - 1);
/* 404:458 */     for (int i = 0; i < length; i += 2)
/* 405:    */     {
/* 406:460 */       dataRead = readWord(offset++);
/* 407:462 */       if (i + 1 < data.length)
/* 408:    */       {
/* 409:464 */         Hi = (byte)(dataRead & 0xFF);
/* 410:465 */         data[(i + 1)] = Hi;
/* 411:    */       }
/* 412:    */       else
/* 413:    */       {
/* 414:469 */         Lo = 0;
/* 415:    */       }
/* 416:471 */       Lo = (byte)((dataRead & 0xFF00) >> 8);
/* 417:472 */       data[i] = Lo;
/* 418:    */     }
/* 419:474 */     return data;
/* 420:    */   }
/* 421:    */ }



/* Location:           E:\code\demo\A108DevForBankComm\libs\d2xx.jar

 * Qualified Name:     com.ftdi.j2xx.FT_EE_245R_Ctrl

 * JD-Core Version:    0.7.0.1

 */